#include "MainController.h"

MainController::MainController(QObject *parent) : QObject(parent) {
    mainWindowView = new MainWindowView();
    menuView = new MenuView();
    aboutProgramView = new AboutProgramView();

    consoleController = new ConsoleController();
    gameOptionsController = new GameOptionsController();
    gameController = new GameController(mainWindowView);

    connect(menuView, SIGNAL(actionConsoleSignal()), this, SLOT(openConsole()));
    connect(menuView, SIGNAL(actionOptionsSignal()), this, SLOT(showGameOptions()));
    connect(menuView, SIGNAL(actionChooseFileSignal()), this, SLOT(loadFromFile()));
    connect(menuView, SIGNAL(actionAboutSignal()), this, SLOT(showAboutProgramInfo()));
    connect(menuView, SIGNAL(actionQuitSignal()), this, SLOT(closeApplication()));
}

void MainController::start() {
    //Okienko główne
    mainWindowView->show();

    //Menu
    mainWindowView->setMenuBar(menuView);

    //Kontroler gry
    gameController->start();
}

MainController::~MainController() {
    delete consoleController;
    delete gameOptionsController;
    delete gameController;
    delete mainWindowView;
    delete aboutProgramView;
}

//Sloty
void MainController::loadFromFile() {
    gameController->loadGamesFromFile(mainWindowView->fileDialog());
}

void MainController::openConsole() {
    consoleController->start();
}

void MainController::showGameOptions() {
    gameOptionsController->start();
}

void MainController::showAboutProgramInfo() {
    aboutProgramView->show();
}

void MainController::closeApplication() {
    qApp->exit();   
}
